package model;

import java.io.Serializable;

import javax.persistence.*;

import dtos.MeanOfTransportationDTO;
import dtos.TransportationTypeDTO;

import java.util.LinkedList;
import java.util.List;


/**
 * The persistent class for the transportationType database table.
 * 
 */
@Entity
@NamedQuery(name="TransportationType.findAll", query="SELECT t FROM TransportationType t")
public class TransportationType implements Serializable {
	private static final long serialVersionUID = 1L;

	@Id
	private int transportationTypeID;

	private String company;

	private String flightClass;

	private String trainClass;

	private String type;

	private String vehicleType;

	//bi-directional many-to-one association to MeanOfTransportation
	@OneToMany(mappedBy="transportationType",cascade={CascadeType.PERSIST})
	private List<MeanOfTransportation> meanOfTransportations;

	public TransportationType() {
	}
	
	public TransportationType(TransportationTypeDTO type){
		
		this.transportationTypeID = type.getTransportationTypeID();
		this.company = type.getCompany();
		this.flightClass = type.getFlightClass();
		this.trainClass = type.getTrainClass();
		this.type = type.getType();
		this.vehicleType = type.getVehicleType();
	}
	
	public TransportationTypeDTO getDTO(){
		TransportationTypeDTO t = new TransportationTypeDTO();
		t.setCompany(this.company);
		t.setFlightClass(this.flightClass);
		//t.setMeanOfTransportations(this.getMeanOfTransportationsDTO());
		t.setTrainClass(this.trainClass);
		t.setTransportationTypeID(this.transportationTypeID);
		t.setType(this.type);
		t.setVehicleType(this.vehicleType);
		return t;
		
	}

	public int getTransportationTypeID() {
		return this.transportationTypeID;
	}

	public void setTransportationTypeID(int transportationTypeID) {
		this.transportationTypeID = transportationTypeID;
	}

	public String getCompany() {
		return this.company;
	}

	public void setCompany(String company) {
		this.company = company;
	}

	public String getFlightClass() {
		return this.flightClass;
	}

	public void setFlightClass(String flightClass) {
		this.flightClass = flightClass;
	}

	public String getTrainClass() {
		return this.trainClass;
	}

	public void setTrainClass(String trainClass) {
		this.trainClass = trainClass;
	}

	public String getType() {
		return this.type;
	}

	public void setType(String type) {
		this.type = type;
	}

	public String getVehicleType() {
		return this.vehicleType;
	}

	public void setVehicleType(String vehicleType) {
		this.vehicleType = vehicleType;
	}

	public List<MeanOfTransportation> getMeanOfTransportations() {
		return this.meanOfTransportations;
	}
	
	public List<MeanOfTransportationDTO> getMeanOfTransportationsDTO() {
		List<MeanOfTransportationDTO> res = new LinkedList<MeanOfTransportationDTO>();
		for (MeanOfTransportation t : this.meanOfTransportations){
			res.add(t.getDTO());
		}
		return res;
		
	}

	public void setMeanOfTransportations(List<MeanOfTransportation> meanOfTransportations) {
		this.meanOfTransportations = meanOfTransportations;
	}

	public MeanOfTransportation addMeanOfTransportation(MeanOfTransportation meanOfTransportation) {
		getMeanOfTransportations().add(meanOfTransportation);
		meanOfTransportation.setTransportationType(this);

		return meanOfTransportation;
	}

	public MeanOfTransportation removeMeanOfTransportation(MeanOfTransportation meanOfTransportation) {
		getMeanOfTransportations().remove(meanOfTransportation);
		meanOfTransportation.setTransportationType(null);

		return meanOfTransportation;
	}

}